<template>
	<view class="consulation">
		<nav-bar :title="`聊天${msgNm !== 0 ? `(${msgNm})` : ''}`"></nav-bar>
		<view class="consulation-list">
			<view class="per" @click="chat(per)" v-for="(per,index) in friendList" :key="index">
				<image class="avatar" :src="per.imgUrl" mode=""></image>
				<view class="msg">
					<view class="msg-top">
						<view class="name">{{per.name}}</view>
						<text class="date">2021/2/16</text>
					</view>
					<view class="msg-cont">
						{{per.msg}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import NavBar from '../../components/nav-bar/nav-bar.vue'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				msgNm: 10,
				friendList: [{
						name: 'DEMO1',
						imgUrl: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202007%2F18%2F20200718230848_HveYa.thumb.400_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg',
						id: '',
						msg: '今天怎么样'
					},
					{
						name: 'DEMO2',
						imgUrl: 'https://img2.woyaogexing.com/2021/02/08/2e89dbcb73a14a0eb8f283164cb55648!400x400.jpeg',
						id: '',
						msg: '背景换一个'
					},
					{
						name: 'DEMO3',
						imgUrl: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202007%2F18%2F20200718230848_HveYa.thumb.400_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg',
						id: '',
						msg: '新年快乐'
					}
				]
			}
		},
		mounted() {
			this.getNum()
		},
		methods: {
			chat(id) {
				uni.navigateTo({
					url: `./consulation?id=${id}`,
					animationDuration: 300,
					animationType: 'pop-in'
				})
			},
			getNum() {
				this.msgNm = parseInt(Math.random() * 10)
			}
		}
	}
</script>

<style lang="less" scoped>
	.consulation {
		width: 100%;
		min-height: 100%;
		background-color: #F3F3F3;
	}

	.consulation-list {
		width: 100%;
		display: flex;
		flex-direction: column;
		padding: 0 30rpx;
		box-sizing: border-box;

		.per {
			width: 100%;
			height: 120rpx;
			border-bottom: 1rpx solid #ccc;
			display: flex;
			flex-direction: row;
			align-items: center;

			.avatar {
				width: 100rpx;
				height: 100rpx;
				border-radius: 10rpx;
				margin-right: 20rpx;
				display: inline-block;
			}

			.msg {
				flex: 1;
				display: flex;
				flex-direction: column;

				.msg-top {
					width: 100%;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;

					.name {
						font-size: 28rpx;
						font-weight: bold;
						color: #333333;
					}

					.date {
						font-size: 24rpx;
						color: #666;
					}
				}

				.msg-cont {
					font-size: 25rpx;
					color: #666;
				}
			}
		}
	}
</style>
